/* $Id: listtable.js 14980 2008-10-22 05:01:19Z testyang $ */

if (typeof Ajax != 'object')
{
    alert('Ajax object doesn\'t exists.');
}

if (typeof Utils != 'object')
{
    alert('Utils object doesn\'t exists.');
}
var url = "flow.php?step=done";
var order = new Object;


order.Info = new Object;
order.Info.AddressId;
order.Info.Message;
order.Info.PayId = 1;
order.Info.CouponId;
order.Info.Rid;
    
/*提交订单*/
order.SumbitOrder = function()
{
    if (!isNull(order.Info.PayId)) {
        order.Info.PayId=$(".payment:checked").val();
    };
    if (!isNull(order.Info.Message)) {
        order.Info.Message=$("#postscript").val();
    };

    $.post(url, {'order' : order.Info},
    this.ReturnOrder
    ,'JSON');
}
/*订单提交回调*/
order.ReturnOrder = function  (data) {
    /*提交失败时提示错误*/
    if (data.error > 0 && data.error != 602) {
        Ctf(data.message,"location.reload();");
    };
    if (data.error == 602) {
        Ctf(data.message,"location.href='flow';","location.reload();");
    };
    if (typeof(data.content) == "undefined") {
        /* 如果定义支付方式则未生成订单 */
        Ctf(data.message,"window.location.href = 'user.php?act=order_list'");
    }
    /*货到付款提交成功*/
    if (data.content.payId === 3) {
        window.location.href='flow.php?step=to_success&order_id='+data.content.orderId;
    }
    /*支付宝提交成功*/
    if (data.content.payId === 1) {
        var action = data.content.payUrl;
        form = $("<form></form>");
        form.attr('action',action);
        form.attr('method','post');
        form.attr('target','_blank');
        form.appendTo("body");
        form.css('display','none');
        form.submit();
        var toUrl = 'window.location.href = "user.php?act=order_list"';
        setTimeout(toUrl, 1500);
    }
}


/*计算订单费用*/
order.Cost = function (){
    $.post('flow.php?step=select_coupon', {'order' : order.Info},
    this.ReturnCost
    ,'JSON');

}

/*计算订单费用*/
order.ReturnCost = function (data){
    if (data.error>0) {

    }
    else{
        $('#ECS_ORDERTOTAL').html(data.content);
    };
}





/*改变支付方式*/
/*
  对象
  地址ID
  支付方式ID
*/
// order.selectPayment = function(obj, address_id, payment){
//   if (selectedPayment == obj && !payment)
//   {
//     return;
//   }
//   else
//   {
//     selectedPayment = obj;
//   }
//   if(payment){
//     Ajax.call('flow.php?step=select_payment&rid='+flow_rid+'&address_id='+address_id, 'payment=' + payment, orderSelectedResponse, 'GET', 'JSON');
//   }else{
//     Ajax.call('flow.php?step=select_payment&rid='+flow_rid+'&address_id='+address_id, 'payment=' + obj.value, orderSelectedResponse, 'GET', 'JSON');
//   }
// }






function isNull(data){
return (data == "" || data == undefined || data == null) ? false : true; 
}


